const app = getApp();
Page({
  data: {
      array: ['本年', '本季度','本月'],
      objectArray: [
          {
              id: 0,
              name: '本年'
          },
          {
              id: 1,
              name: '本季度'
          },
          {
              id: 2,
              name: '本月'
          }
      ],
      index: 0,
      selectType: 'year',
      tokenID: '',   
      msgList:[]               
  },
  bindPickerChange: function (e) {
      if (e.detail.value == 0)
      {
          this.setData({
              index: e.detail.value,
              selectType: 'year'
          })
      }else if (e.detail.value == 1) 
      {
          this.setData({
              index: e.detail.value,
              selectType: 'quarter'
          })
       }else if (e.detail.value == 2) 
       {
          this.setData({
              index: e.detail.value,
              selectType: 'month'
          })
        }
      this.gtemomentList();
  },
  onLoad: function (options) {
      var _this = this;
      _this.setData({
          tokenID: app.data.tokenID
      })
      _this.gtemomentList()
  },
  gtemomentList: function (type) {
      var _this = this;
      wx.request({
          url: app.data.api + 'rankinglist/rankinglist',
          data: {
              "token": _this.data.tokenID,
              "type": _this.data.selectType
          },
          method: "POST",
          header: { 'content-type': 'application/x-www-form-urlencoded' },
          success: function (res) {
              if (res.data.status)
              {
                  var moment_list = [];

                  for (var i = 0; i < res.data.data.length; i++) {

                      moment_list.push(res.data.data[i]);
                  }
                  _this.setData({
                      msgList: moment_list
                  })
              }else{
                  wx.showModal({
                      title: '提示',
                      content: res.data.msg,
                      success: function (res) {
                          if (res.confirm) {
                              wx.redirectTo({
                                  url: '../login/login'
                              })
                          } else if (res.cancel) {
                              wx.redirectTo({
                                  url: '../login/login'
                              })
                          }
                      }
                  });
              }
          }
      })
  }
})